﻿package com.everydayflash.pv3d {
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.events.TextEvent;
	
	import flash.net.navigateToURL;

	public class TopBar extends Sprite {
		
		private var bg:Sprite;
		private var style:TextFormat;
		private var ins:TextField;
		private var link:TextField;
		
		private var instruction:String;
		private var inverted:Boolean;
		
		public function TopBar(instruction:String = "[...]", inverted:Boolean = false) {
			this.inverted = inverted;
			style = new TextFormat();
			style.font = "Arial";
			style.size = 12;
			style.color = (inverted) ? 0xffffff : 0x000000;
			
			this.instruction = instruction;

			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			bg = new Sprite();
			bg.graphics.beginFill((inverted) ? 0x000000 : 0xffffff);
			bg.graphics.drawRect(0, 0, stage.stageWidth, 30);
			addChild(bg);

			ins = new TextField();
			ins.autoSize = TextFieldAutoSize.LEFT;
			ins.defaultTextFormat = style;
			ins.htmlText = instruction;
			ins.x = 9;
			ins.y = 6;
			addChild(ins);
			
			link = new TextField();
			link.autoSize = TextFieldAutoSize.LEFT;
			link.defaultTextFormat = style;
			link.htmlText = "<a href='http://www.everydayflash.com'>www.everydayflash.com</a>";
			link.x = stage.stageWidth - 9 - link.textWidth;
			link.selectable = false;
			link.y = 6;
			addChild(link);
		}
		
		public function resize():void {
			bg.width = stage.stageWidth;
			link.x = stage.stageWidth - 9 - link.textWidth;
		}
		
		public function update(newInstr:String):void {
			instruction = newInstr;
			ins.htmlText = instruction;
		}
		
		public function overrideLink(newContent:String):void {
			link.htmlText = newContent;
			link.x = stage.stageWidth - 9 - link.textWidth;
		}
	}
	
}